var did="";
$(function()
    {
       $("#sub").click(function()
        {
           var arr=new Array();
           arr['sname']=$("#name").val();
           arr['stel']=$("#mobile").val();
           arr['addr']=$("#Province").val()+"-"+$("#Country").val()+"-"+$("#Town").val();
           arr['addrInfo']=$("#goodsStreet").val();
           arr['email']=$("#mail").val();
           //ajax发送
           $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
           $.post("/userAddr",{"sname":arr['sname'],"stel":arr['stel'],"addr": arr['addr'],"addrInfo":arr['addrInfo'],"email":arr['email'],},function(msg)
            {
                alert(msg);
            });
        });
       $("#sub2").click(function()
       {
           var arr=new Array();
           arr['sname']=$("#name2").val();
           arr['stel']=$("#mobile2").val();
           arr['addr']=$(".Province2").val()+"-"+$(".Country2").val()+"-"+$(".Town2").val();
           arr['addrInfo']=$("#goodsStreet2").val();
           arr['email']=$("#mail2").val();

             $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
             $.post("/userAddr/"+did,{"_method":"PUT","sname":arr['sname'],"stel":arr['stel'],"addr": arr['addr'],"addrInfo":arr['addrInfo'],"email":arr['email']},function(msg)
                {
                   alert(msg);
                });

       })
    });

    function addrcreate()
{
    $("#insertAdd").css("display","block");
    $("#zhao").css("display","block");
    $("#zhao").css("height",$(document).height());
    $("#zhao").css("weight",$(document).weight());

}
function hideLayer()
{
    $("#insertAdd").css("display","none");
    $("#insertAdd2").css("display","none");
    $("#zhao").css("display","none");
}
function edit(id)
{
    $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
    $.get("/userAddr/"+id,{"id":id},function(msg)
        {
            msgss=JSON.parse(msg);
            $("#insertAdd2").css("display","block");
            $("#zhao").css("display","block");
            $(".name2").val(msgss.sname);
            $("#mobile2").val(msgss.stel);
            $("#goodsStreet2").val(msgss.addrInfo);
            $("#mail2").val(msgss.email);
            // console.log(msgss.sname);
        });
    did=id;
}
function pop(id)
{

               $.get("/userAddr/"+id+"/edit",{"id":id},function(msg)
                {
                    alert(msg);
                });
}
function deleted(id)
{
     $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
     $.post("/userAddr/"+id,{"_method":"DELETE"},function(msg)
        {
               if(msg==1){
                alert("删除成功");
               }else{
                alert("删除失败");
               }
        });
}


